#include "stdafx.h"

#include "..\CmdLineMatcher.h"

namespace Fast
{

TESTCLASS(CmdLineMatcherTests)
{
	TESTMETHOD(BadArgTest)
	{
		try {
			CmdLineMatcher clm(0, NULL);
		} catch(HRESULT& hr) {
			TDD_VERIFY(hr == E_INVALIDARG);
			return;
		}
		TDD_FAILURE("expected exception not thrown!");
	}
	TESTMETHOD(NoArgsMeansMatchEverything)
	{
		char* args = NULL;
		CmdLineMatcher clm(1, &args);
		TDD_VERIFY(true == clm.Matches("foo"));
		TDD_VERIFY(true == clm.Matches("bar"));
	}
	TESTMETHOD(SingleNamespaceTestMeansRunAllTestMethodsInThatNamespace)
	{
		char* args[] = { "ignored.exe", "namespace1" };
		CmdLineMatcher clm(2, args);
		TDD_VERIFY(false == clm.Matches("hi"));
		TDD_VERIFY(true  == clm.Matches("namespace1"));
		TDD_VERIFY(true  == clm.Matches("namespace1::namespace2"));
		TDD_VERIFY(true  == clm.Matches("namespace1::class"));
		TDD_VERIFY(true  == clm.Matches("namespace1::class.test"));
	}

	TESTMETHOD(LoopOverMultipleArgsTest)
	{
		char* args[] = { "ignored.exe", "namespace2", "namespace1" };
		CmdLineMatcher clm(3, args);
		TDD_VERIFY(false == clm.Matches("hi"));
		TDD_VERIFY(true  == clm.Matches("namespace1"));
		TDD_VERIFY(true  == clm.Matches("namespace1::namespace2"));
		TDD_VERIFY(true  == clm.Matches("namespace1::class"));
		TDD_VERIFY(true  == clm.Matches("namespace1::class.test"));
	}

	TESTMETHOD(LongTestSpecTest)
	{
		char* args[] = { "ignored.exe", "namespace2" };
		CmdLineMatcher clm(2, args);
		TDD_VERIFY(false == clm.Matches("namespace2long"));
		TDD_VERIFY(true == clm.Matches("namespace2::long"));
		TDD_VERIFY(true == clm.Matches("namespace2.long"));
	}
};

}
